<html>
    <head>
        <meta charset="UTF-8">
        <meta http-equiv="X-UA-Compatible" content="IE=edge">
        <meta name="viewport" content="width=device-width,initial-scale=1.0">
        <title>添加信息页面</title>
    </head>
    <body>
        <center>
            <?php
            include "common\menu.php";
            require "common\conn.php";
            ?>       
            <h3>添加学生信息</h3>
            <form action="" method="post">
                <table>
                    <tr>
                        <td>学号：</td>
                        <td><input type="text" name="stu_no" required></td>
                    </tr>
                    <tr>
                        <td>姓名：</td>
                        <td><input type="text" name="stu_name" required></td>
                    </tr>
                    <tr>
                        <td>性别：</td>
                        <td>男<input type="radio" name="gender" value="男" required>
                        女<input type="radio" name="gender"  value="女" required></td>
                    </tr>
                    <tr>
                        <td>电话：</td>
                        <td><input type="text" name="telephone" required></td>
                    </tr>
                    <tr>
                        <td>年龄：</td>
                        <td><input type="text" name="age" required></td>
                    </tr>
                    <tr>
                        <td>学院：</td>
                        <td><input type="text" name="college" required></td>
                    </tr>
                    <tr align="center">
                        <td colspan="2">
                            <input type="submit" value="添加">
                            <input type="reset" value="重置">
                        </td>
                    </tr>
                </table>
            </form>
            <?php
            if($_SERVER['REQUEST_METHOD'] == 'POST') { //当表单发送方式为POST时才输出表单
                $stu_no = $_POST['stu_no'];
                $stu_name = $_POST['stu_name'];
                $gender = $_POST['gender'];
                $telephone = $_POST['telephone'];
                $age = $_POST['age'];
                $college = $_POST['college'];
                $sql = "INSERT into stu(stu_no,stu_name,gender,telephone,age,college) values ('{$stu_no}','{$stu_name}','{$gender}','{$telephone}','{$age}','{$college}')";                
                $result = $pdo->exec($sql);
                if($result>0) {
                    header('Location:index.php');
                } else {
                    echo "添加失败，当前列表中已有重复名单";
                }
            }

            ?>   
        </center>
    </body>
</html>